var system = require('system');
var fs = require('fs');

console.log('hi');
console.log(system.stdin);


var stdin = fs.open('/dev/stdin', 'r');

// Damn, PhantomJS only has readLine() and read() the whole file.  Crap.

//console.log(stdin.readLine());
//var s = stdin.readLine();
var s = stdin.read(3);

// NOTE: It trims the newline!
console.log('length: ' + s.length);

console.log('stdin: ' +  s + ' ... ');

var out = JSON.stringify({a:1});

// I guess this goes to stdout
console.log(out);

// This is also on stdout!  Doh.
console.debug('console.debug');
console.log('console.log');
console.error('console.error');

console.log('CONSOLE');

for (var p in console) {
  console.log(p);
}

phantom.exit();
